<template>
  <div>
    <el-pagination
      v-if="total > 0"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    total: {
      type: Number,
      required: true,
      default: 0
    },
    currentPage: {
      type: Number,
      default: 1
    },
    pageSizes: {
      type: Array,
      default: () => [10, 20, 30, 40, 40]
    },
    pageSize: {
      type: Number,
      default: 20
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
    }
  },
  methods: {
    handleSizeChange(newPageSize) {
      this.$emit('update:pageSize', newPageSize)
      if (this.currentPage !== 1) {
        this.$emit('update:currentPage', 1)
      }
      this.$emit('pagination')
    },
    handleCurrentChange(newCurrentChange) {
      this.$emit('update:currentPage', newCurrentChange)
      this.$emit('pagination')
    }
  }
}
</script>

<style lang="scss" scoped></style>
